A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s
body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to
such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing
function parameters that are not being utilized is considered best practice.
Exceptions
There are some cases when you want to have an unused parameter (usually because the function has to conform to a fixed prototype, or because it is
virtual, or it will be called from a template). In this case, and if the parameter is never used, an accepted practice is to leave it unnamed. If it
is only sometimes used (for instance, depending on conditional compilation), you may, since C++17, use the [[maybe_unused]]
attribute to
be explicit about it.
void f([[maybe_unused]] int i) {
assert(i < 42); // In optimized mode, this assert will be removed, and "i" will be unused
}
In case of Objective-C, it is acceptable to have unused parameters if the method is supposed to be overridden.